/**
 * Include this file for running tests (replace with boot.js)
 */
$(function() {
    // for easy reference, kinda like an import statement
    var arcomage = net.andersand.arcomage;

    var setupArcomage = function() {
        // Set up game runtime
        var game = new arcomage.Game();
        var human = new arcomage.Player({ai:false});
        var computer = new arcomage.Player({ai:true});
        game.players.push(human);
        game.players.push(computer);
        game.createDeck();
        game.init();
        return game;
    };

    function test(scenarioName, fnTest, expected) {
        var result = new net.andersand.test.Test(scenarioName, fnTest, expected).run();
        if (result === true) {
            successfulTests++;
        }
        else {
            failedTests++;
        }
    }

    var logger = net.andersand.util.logger;
    // place console at top of the page when testing
    $("#main").prepend(logger.get()).css("overflow", "auto");

    logger.log("Running tests ...");
    var successfulTests = 0,
            failedTests = 0;

    // test the testing framework basics
    test("basic test", function() { return false; }, false);
    test("basic test", function() { return true; }, true);
    test("basic test", function() { return 0; }, 0);
    test("basic test", function() { return 1; }, 1);
    test("basic test", function() { return ""; }, "");
    test("basic test", function() { return null; }, null);

    // basic game init tests
    test("arcomage got players", function() {
        var arcomage = setupArcomage();
        return arcomage.players.length;
    }, 2);
    test("player add card", function() {
        var card = new arcomage.Card(arcomage.rulebase["ArcoRed01"][0]);
        var player = new arcomage.Player();
        player.addCard(card);
        return player.cards.length;
    }, 1);
    test("raphael custom group", function() {
        var r = new Raphael(0,0,0,0);
        return typeof r.group;
    }, "function");
    test("game create deck", function() {
        var game = new arcomage.Game();
        game.createDeck();
        return game.getDeck().length;
    }, 123);
    test("player remove card", function() {
        var card1 = new arcomage.Card(arcomage.rulebase["ArcoRed01"][0]),
            card2 = new arcomage.Card(arcomage.rulebase["ArcoRed02"][0]),
            card3 = new arcomage.Card(arcomage.rulebase["ArcoRed03"][0]);
        var player = new arcomage.Player();
        player.addCard(card1);
        player.addCard(card2);
        player.addCard(card3);
        player.removeCard(card2);
        return player.cards.length;
    }, 2);


    logger.prepend("# Tests successful : " + successfulTests, (failedTests == 0 ? "successful" : ""));
    logger.prepend("# Tests failed : " + failedTests, (failedTests > 0 ? "faulty" : ""));
    logger.log("Done running tests");    


});
